package com.ai.bitcoin.jpa.service.impl;

import com.ai.bitcoin.jpa.dao.BccIndexInfoCrawlDao;
import com.ai.bitcoin.jpa.dao.BccIndexInfoDao;
import com.ai.bitcoin.jpa.entity.BccIndexInfo;
import com.ai.bitcoin.jpa.entity.BccIndexInfoCrawl;
import com.ai.bitcoin.jpa.service.BccIndexInfoCrawlService;
import com.ai.bitcoin.jpa.service.BccIndexInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Jason
 * @date 2018/4/11
 **/
@Component
public class BccIndexInfoServiceImpl implements BccIndexInfoService {
    @Autowired
    BccIndexInfoDao dao;

    @Override
    public Page<BccIndexInfo> findByBccIdAndBatchNo(String bccId, String batchNo, Pageable pageable) {
        return dao.findByBccIdAndBatchNo(bccId, batchNo, pageable);
    }

    @Override
    public List<BccIndexInfo> findByBccIdAndBatchNo(String bccId, String batchNo) {
        return dao.findByBccIdAndBatchNo(bccId, batchNo);
    }

    @Override
    @Transactional
    public BccIndexInfo save(BccIndexInfo bccIndexInfo) {
        return dao.save(bccIndexInfo);
    }

    @Override
    public List<BccIndexInfo> findByBccIdAndIndexTitleYesterday(String bccId, String indexTitle) {
        return dao.findByBccIdAndIndexTitleYesterday(bccId, indexTitle);
    }

    @Override
    public List<BccIndexInfo> findByBccIdAndRecordState(String bccId, String recordState) {
        return dao.findByBccIdAndRecordState(bccId, recordState);
    }

    @Override
    @Transactional
    public void updateRank(String unPublishBatchNo) {
        dao.deleteOldBatch(unPublishBatchNo);
        dao.updateNewBatch2Publish(unPublishBatchNo);
    }

    @Override
    public Page<BccIndexInfo> findByRecordState(String recordState, Pageable pageable) {
        return dao.findByRecordState(recordState, pageable);
    }

    @Override
    @Transactional
    public void deleteNoPublish() {
        dao.deleteNoPublish();
    }

    @Override
    public List<BccIndexInfo> findByBatchNo(String batchNo) {
        return dao.findByBatchNo(batchNo);
    }

    @Override
    public List<BccIndexInfo> findByBatchNoAndIndexTitle(String batchNo, String indexTitle) {
        return dao.findByBatchNoAndIndexTitle(batchNo, indexTitle);
    }
}
